<?php 
if($this->session->userdata('role') != null){
	if($this->session->userdata('role') == 1){
include 'include/header.php';
?>
<script>
function modal_preview_data(e){
				e.preventDefault();
				$('#ajaxModal').remove();
				var url = $(e.target).attr('href');
				$('<div class="modal" id="ajaxModal"><div class="modal-body"></div></div>').appendTo('body');
				 $('#ajaxModal').modal();
				 $('#ajaxModal').load(url);
				//console.log(url.toString());
}
</script>

	<div class="form-group">
		<!--input type="file" name="file" id="file" readonly="true" multiple="multiple"-->
		<button class="btn btn-primary" onclick="modal_csv()">Upload Data CSV</button>
	</div>	

<?php 
if(!$kuesioner){
 echo 'Belum ada data';
} else{
if(count($kuesioner) < 6){
	$d = 0;
} else
	{
		$d = floor(count($kuesioner)/6);
	}

$b = count($kuesioner)%6;
//var_dump(count($kuesioner));
//var_dump($d);
//var_dump($b);
	
$indeks_data = 0;

for($c = 0; $c < $d; $c++){
?>
<div class="form-group">
<div class="row">
<?php

$a = 1;
for($e = 0; $e < 6; $e++){
?>
  <div class="col-sm-6 col-md-2">
    <div class="thumbnail">
      <div class="caption" style="word-wrap: break-word;max-width: 189px;">
		<img src="<?php echo base_url().'excel.jpg'; ?>" alt="..." height="60" width="60">
        <h4 style="text-overflow: ellipsis; white-space: nowrap; overflow: hidden;"><?php echo $kuesioner[$indeks_data]['nama_kuesioner']; ?></h4>
        <p style="text-overflow: ellipsis; white-space: nowrap; overflow: hidden;"><?php echo $kuesioner[$indeks_data]['deskripsi']; ?></p>        
		<p style=""><?php echo ($kuesioner[$indeks_data]['reliabilitas'] == 1)? "Reliabel" : " Tidak Reliabel" ?></p>        
        <p style=""><?php echo ($kuesioner[$indeks_data]['validitas'] == 1)? "Valid" : " Tidak Valid" ?></p>
		<div class="row" hidden style="margin-left:0px">
		
			<a href="<?php echo base_url().'index.php/uji/data/'.$kuesioner[$indeks_data]['id_kuesioner'];?>" ><img src="<?php echo base_url().'assets/img/test.png'; ?>" width="20px" title="Pengujian data"></img></a>
			<a href="#" ><img src="<?php echo base_url().'assets/img/preview_data.png'; ?>" width="20px" href="<?php echo base_url().'index.php/kuesioner/lihat_data_responden/'.$kuesioner[$indeks_data]['id_kuesioner'];?>" onclick="modal_preview_data(event)" title="lihat data"></img></a>
			<a href="#" ><img src="<?php echo base_url().'assets/img/preview_data.png'; ?>" width="20px" onclick="modal_keterangan_publish(event,<?php echo $kuesioner[$indeks_data]['id_kuesioner'];?>)" title="Ubah Keterangan"></img></a>
			<button onclick="delete_penelitian(<?php echo $kuesioner[$indeks_data]['id_kuesioner'];?>, event)" class="btn btn-danger" title="Hapus Penelitian" style="margin-left: 75px;">X</button>
		</div>
      </div>
    </div>
  </div>
<?php 
$indeks_data++;
}
?>
</div> 
</div>
<?php
}

?>
<div class="form-group">
	<div class="row">
	<?php
		for($e = 0; $e < $b; $e++){
	?>
	<div class="col-sm-6 col-md-2">
    <div class="thumbnail">
      <div class="caption" style="word-wrap: break-word;max-width: 189px;">
		<img src="<?php echo base_url().'excel.jpg'; ?>" alt="..." height="60" width="60">
        <h4 style="text-overflow: ellipsis; white-space: nowrap; overflow: hidden;"><?php echo $kuesioner[$indeks_data]['nama_kuesioner']; ?></h4>
        <p style="text-overflow: ellipsis; white-space: nowrap; overflow: hidden;"><?php echo $kuesioner[$indeks_data]['deskripsi']; ?></p>        
		<p style=""><?php echo ($kuesioner[$indeks_data]['reliabilitas'] == 1)? "Reliabel" : " Tidak Reliabel" ?></p>        
        <p style=""><?php echo ($kuesioner[$indeks_data]['validitas'] == 1)? "Valid" : " Tidak Valid" ?></p>
		<div class="row" hidden style="margin-left:0px">
			<a href="<?php echo base_url().'index.php/uji/data/'.$kuesioner[$indeks_data]['id_kuesioner'];?>" ><img src="<?php echo base_url().'assets/img/test.png'; ?>" width="20px" title="Pengujian data"></img></a>
			<a href="#" ><img src="<?php echo base_url().'assets/img/preview.png'; ?>" width="20px" href="<?php echo base_url().'index.php/kuesioner/lihat_data_responden/'.$kuesioner[$indeks_data]['id_kuesioner'];?>" onclick="modal_preview_data(event)" title="lihat data"></img></a>
			<a href="#" ><img src="<?php echo base_url().'assets/img/preview_data.png'; ?>" width="20px" onclick="modal_keterangan_publish(<?php echo $kuesioner[$indeks_data]['id_kuesioner'];?>)" title="Ubah Keterangan"></img></a>
			<button onclick="delete_penelitian(<?php echo $kuesioner[$indeks_data]['id_kuesioner'];?>, event)" class="btn btn-danger" title="Hapus Penelitian" style="margin-left: 75px;">X</button>
		</div>
      </div>
    </div>
  </div>
	<?php
	$indeks_data++;
		}
	}
	?>
	</div>
</div>


<form action="<?php echo base_url().'index.php/uji/uji_data_csv';?>" method="post" enctype="multipart/form-data" data-parsley-validate>
	<div id="modal_data_csv" class="modal fade bs-example-modal-sm" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel" aria-hidden="true">
		<div class="modal-dialog modal-sm">
			<div class="modal-content">
				<div class="modal-header">
					<h4 class="modal-title" id="myModalLabel">Form Upload Data CSV</h4>
				</div>
				<div class="modal-body">
					<div class="form-group">
						<input class="form-control" placeholder="Nama data" name="nama_data" data-parsley-trigger="change" required>
						<input class="form-control" placeholder="Deskripsi data" name="deskripsi_data" data-parsley-trigger="change" required>
					</div>
					<div class="form-group">
						<label>Upload Data</label>
						<input type="file" name="file_csv" id="file_csv" readonly="true" data-parsley-trigger="change" required>
					</div>
					<div class="form-group">
						<label>Upload Metodologi Penelitian</label>
						<input type="file" name="file" id="file" readonly="true">
					</div>
					<div class="form-group">
						<label>Keterangan</label>
						<input type="checkbox" name="pp" value="1">Publish Penelitian</input>
						<input type="checkbox" name="pm" value="1">Publish Metodologi</input>
						<input type="checkbox" name="pd" value="1">Publish Data</input>
					</div>
				</div>
				<div class="modal-footer">
					<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
					<button id="btn_tambah" type="submit" class="btn btn-primary">Tambah</button>
				</div>
			</div>
		</div>
	</div> 
</form>
	<div id="modal_keterangan_publish" class="modal fade bs-example-modal-sm" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel" aria-hidden="true">
		<div class="modal-dialog modal-sm">
			<div class="modal-content">
				<div class="modal-header">
					<h4 class="modal-title" id="myModalLabel">Edit Keterangan Publish</h4>
				</div>
				<div class="modal-body">
					<label>*centang keterangan yang diinginkan</label>
					<div class="form-group">
						<label>Keterangan</label>
						<input id="id_kuesioner" hidden>
						<input type="checkbox" id="pp" name="pp">Publish Penelitian</input>
						<input type="checkbox" id="pm" name="pm">Publish Metodologi</input>
						<input type="checkbox" id="pd" name="pd">Publish Data</input>
					</div>
					
				</div>
				<div class="modal-footer">
					<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
					<button id="btn_tambah" type="submit" class="btn btn-primary" onclick="update_keterangan()">Simpan</button>
				</div>
			</div>
		</div>
	</div> 
<?php
include 'include/footer.php';
?>
<script>
$(document).ready(function(){

	$(".thumbnail").hover(function() {
			$(this).children('.caption').children('.row').css('display', 'block');
			$(this).children('.caption').children('h4').css('text-overflow','');
			$(this).children('.caption').children('h4').css('overflow','');
			$(this).children('.caption').children('h4').css('white-space','');
			$(this).children('.caption').children('p').css('text-overflow','');
			$(this).children('.caption').children('p').css('overflow','');
			$(this).children('.caption').children('p').css('white-space','');
		  }, function() {
			$(this).children('.caption').children('.row').css('display', 'none');
			$(this).children('.caption').children('h4').css('text-overflow','ellipsis');
			$(this).children('.caption').children('h4').css('overflow','hidden');
			$(this).children('.caption').children('h4').css('white-space','nowrap');
			$(this).children('.caption').children('p').css('text-overflow','ellipsis');
			$(this).children('.caption').children('p').css('overflow','hidden');
			$(this).children('.caption').children('p').css('white-space','nowrap');
			});
			
	$('#file').on( 'change', function() {
	   myfile= $( this ).val();
	   var ext = myfile.split('.').pop();
	   if(ext=="pdf"){
		   
	   } else{
			alert('format file harus pdf!');
			$('#file').val('');
	   }
	});
	
	$('#file_csv').on( 'change', function() {
	   myfile= $( this ).val();
	   var ext = myfile.split('.').pop();
	   if(ext=="csv"){
		   
	   } else{
			alert('format file harus csv!');
			$('#file_csv').val('');
	   }
	});
})

function modal_csv()
{
	$('#modal_data_csv').modal('show');
}

function modal_keterangan_publish(id)
{
	$.post('<?php echo base_url(); ?>index.php/uji/get_keterangan/'+id, {
			}, function(data){
					$('#id_kuesioner').val();
					$('#pp').removeAttr('checked');
					$('#pm').prop('checked', false);
					$('#pd').prop('checked', false);
					$.each(data, function(key, value) {
						$.each(value, function(key1, value1) {
							if(value1['publish'] == 1){
								$('#pp').prop('checked', true);
							} else
								{
									$('#pp').prop('checked', false);
								}
							if(value1['publish_metodologi'] == 1){
								$('#pm').prop('checked', true);
							} else
								{
									$('#pm').prop('checked', false);
								}
							if(value1['publish_data'] == 1){
								$('#pd').prop('checked', true);
							} else
								{
									$('#pd').prop('checked', false);
								}
							$('#id_kuesioner').val(value1['id_kuesioner']);
						});
					});
				}, 'json');
				
	$('#modal_keterangan_publish').modal('show');
}

function update_keterangan()
{
	if($('#pp').is(':checked')){
		var pp = 1;
	} else
		{
			var pp = 0;
		}
	if($('#pm').is(':checked')){
		var pm = 1;
	} else
		{
			var pm = 0;
		}	
	if($('#pd').is(':checked')){
		var pd = 1;
	} else
		{
			var pd = 0;
		}
		
	$.post('<?php echo base_url(); ?>index.php/uji/update_keterangan/', {
		id_kuesioner: $('#id_kuesioner').val(),
		pp: pp,
		pm: pm,
		pd: pd
	}, function(data){
		alert('Keterangan telah diubah!');
		});
}

function delete_penelitian(id_kuesioner,e)
	{
	
	var x = confirm('Anda yakin akan menghapus data ini?');
	if(x){
		$.post('<?php echo base_url(); ?>index.php/kuesioner/hapus_penelitian/'+id_kuesioner, {
			});
		} else{e.preventDefault();}
	
	}

</script>
<?php
include 'include/footer.php';
} else{ 
		echo 'Anda belum login, silahkan login terlebih dahulu dengan klik link berikut';
		echo '<a href="'.base_url('index.php/guest').'">Kembali</a>';
	}
} else
	{
		echo 'Anda belum login, silahkan login terlebih dahulu dengan klik link berikut';
		echo '<a href="'.base_url('index.php/guest').'">Kembali</a>';
	}
	
?>